<html>
<head>
    <meta charset="UTF-8">


</head>

<body class="login">


</body>

</html>

<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:sec="http://www.thymeleaf.org/extras/spring-security">
<head th:replace="~{common/head}"></head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">

        <!--左侧导航-->
        <div th:replace="~{common/aside::aside}"></div>
        <!--End 左侧导航-->

        <!--头部信息aside-->
        <div th:replace="~{common/aside::header}"></div>
        <!--End 头部信息aside-->

        <!-- 页面主要内容-->
        <main class="lyear-layout-content">

            <div class="content">
                <h3 class="form-title">物品列表
                    <a href="/item/createItem" sec:authorize="hasAnyAuthority('VIP','ROOT')">添加物品</a>
                    <a href="https://s1.ax1x.com/2020/08/15/dFovDI.jpg">CDK如何兑换</a>
                </h3>
                <h4>本活动最终解释权归天天加班的群主所有</h4>
                <h5>点击要购买的物品图片，即可进入购买下单页面，没有开启秒杀则会以原价购买</h5>
                <h5>下单成功后，在【线上活动->我买到的】中获取cdkey自行兑换，点击下单则会直接扣除相应D点，请确保有足够的D点购买</h5>
            </div>
        </main>
        <!--End 页面主要内容-->
    </div>
</div>

<script type="text/javascript" src="/js/jquery.min.js"></script>
<script type="text/javascript" src="/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/js/perfect-scrollbar.min.js"></script>
<script type="text/javascript" src="/js/main.min.js"></script>
<script src="/js/bootstrap-notify.min.js"></script>
<script type="text/javascript" src="/js/lightyear.js"></script>
<script>
    //定义全局商品数组信息
    var g_itemList = [];
    jQuery(document).ready(function () {
        $.ajax({
            type: "GET",
            url: "/item/list",
            xhrFields: {withCredentials: true},
            success: function (data) {
                if (data.status == "success") {
                    g_itemList = data.data;
                    reloadDom();
                } else {
                    alert("获取商品信息失败，原因为" + data.data.errMsg);
                }
            },
            error: function (data) {
                alert("获取商品信息失败失败，原因为" + data.responseText);
            }
        });

    });


    function reloadDom() {
        for (var i = 0; i < g_itemList.length; i++) {
            var itemVO = g_itemList[i];
            var dom = "<div style='width:20%;float: left' data-id='" + itemVO.id + "' id='itemDetail" + itemVO.id + "'>" +
                "<div class='form-group'>" +
                "<div><img style='width:200px;height:150px' src='" + itemVO.imgUrl + "'/></div>" +
                "</div>" +
                "<div class='form-group'>" +
                "<div><label class='control-label'>" + itemVO.title + (0 === itemVO.stock ? "(卖光了)" : "")  + "</label>" +
                "</div>" +
                "</div>" +
                "<div class='form-group'><label class='control-label'>原价</label>" +
                    "<div>" +
                "<label class='control-label'>" + itemVO.price + "</label>" +
                "</div>" +
                "</div>" +
                "<div class='form-group'>" +
                "<label class='control-label'>卖出数量</label>" +
                "<div><label class='control-label'>" + itemVO.sales + "</label>" +
                "</div></div></div>";
            $(".content").append($(dom));

            $("#itemDetail" + itemVO.id).on("click", function (e) {
                window.location.href = "info?id=" + $(this).data("id");
            });
        }

    }


</script>
<!--图表插件-->
</body>
</html>